export default {
	namespaced: true,
	state: {
		userInfo: uni.getStorageSync('userInfo'),
		address: uni.getStorageSync('address'),
		token: uni.getStorageSync('token'),
		redirectInfo: null  //记录成功登录之后跳转到哪里去
	},

	getters: {
		getuserInfo: state => state.userInfo,
		getRedirectInfo: state => state.redirectInfo,
		getToken: state => state.token,
		getAddress: state => state.address,
		address: state => {
			return state.address && `${state.address.provinceName}${state.address.cityName}${state.address.countyName}`
		},

	},

	mutations: {
		setuserInfo (state, userInfo) {
			state.userInfo = userInfo

			uni.setStorageSync('userInfo', userInfo)
		},

		setRedirectInfo (state, redirectInfo) {
			state.redirectInfo = redirectInfo
		},

		setToken (state, token) {
			state.token = token

			uni.setStorageSync('token', token)
		},

		setAddress (state, address) {
			state.address = address

			uni.setStorageSync('address', address)
		}
	},

	actions: {
		logoutAction ({ commit }) {
			setTimeout(() => {
				commit('setToken', null)
				commit('setuserInfo', null)
			}, 500)
		}
	}
}